package com.gitee.wsl.net

import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.readByte
import io.ktor.utils.io.readUTF8Line
import kotlinx.io.IOException

//JagexTypes
suspend fun ByteReadChannel.readMedium(): Int {
    return (readByte().toInt() shl 16) + (readByte().toInt() shl 8) + readByte().toInt()
}

suspend fun ByteReadChannel.readUByte(): Int {
    return readByte().toInt() and 0xff
}

suspend fun ByteReadChannel.readUMedium(): Int {
    return (readUByte() shl 16) + (readUByte() shl 8) + readUByte()
}

//suspend fun ByteReadChannel.readFields(): Map<String, String> {
//    val fields = mutableListOf<String>()
//    var line = readUTF8Line() ?: throw IOException("$this is closed for reading")
//    while (line.isNotEmpty()) {
//        fields.add(line)
//        line = readUTF8Line() ?: ""
//    }
//    return parseParams(fields)
//}